<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>



    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css">
    <script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>

    <style>
        .layui-form-item .layui-input-inline {
            width: 200px;
        }
        #userForm table tr {
            width: 100%;
            margin: 0 auto;
            display: flex;
            flex-wrap: nowrap;
            justify-content: center;
        }

        #userForm table tr td{
            display: flex;
            flex-wrap: nowrap;
            margin: 10px;
        }

        #userForm table tr td .layui-input{
            width: 200px;
        }

        #userForm table tr td .layui-form-label{
            width: 150px;
        }
    </style>


</head>
<body>

<form class="layui-form" id="userForm">
    <table>
        <div class="app">

            <tr>
                <td>
                    <label class="layui-form-label"> 商品名称:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="goodsName"
                        size="20"/>
                </td>
            </tr>


            <tr>
                <td>
                    <label class="layui-form-label">购买人姓名:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="username"
                        size="20"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label class="layui-form-label">收货地址:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="userAddress"
                        size="20"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label class="layui-form-label">邮编:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="postCode"
                        size="20"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label class="layui-form-label"> 当前余额:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="balance"
                        size="20"/>
                </td>
            </tr>
            <tr>
                <td>

                    <label class="layui-form-label">总价:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="money"
                        size="20"/>


                </td>
            </tr>

            <tr>
                <td>
                    <label class="layui-form-label">请输入二级密码:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="password" name="reaalname"
                        id="password2"
                        size="20"/>
                </td>
            </tr>



            <tr>
                <td>
                    <label class="layui-form-label"></label><input
                        required lay-verify="required" autocomplete="off"  type="button" name="reaalname"
                        id="commit" value="支付"
                        size="20"/>
                </td>
            </tr>

        </div>
    </table>
</form>

<script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="/lib/getUrl.js"></script>


<script>
    layui.use('laydate', function() {
        var laydate = layui.laydate;

//常规用法
        laydate.render({
            elem: '#createtime'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#lastupdatetime'
            ,type: 'datetime'
        });
    })
    layui.use(['form', 'table', `upload`, 'layer', 'jquery', 'laydate'], function () {
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var layer = layui.layer;
        var laydate = layui.laydate;


        var goodsName = request("goodsName");
        var createBy = request("createBy");
        var money = request("money");
        $("#goodsName").val(goodsName);
        $("#username").val(createBy);
        $("#money").val(money);

        $.ajax({
            url: "/user/sessionUser.do",
            type: "get",
            dateType: "json",
            async:false,
            success:function (rec) {

                $.ajax({
                    url: "/bank/findBalance.do",
                    type: "get",
                    dataType: "json",
                    data: {
                    },
                    success: function (r) {
                        var data1 = r.data;
                        $("#balance").val(data1.balance)

                        var data = rec.data;
                        var postCode = data.postCode;
                        var userAddress = data.userAddress;
                        $("#postCode").val(postCode);
                        $("#userAddress").val(userAddress);
                    }
                })

            }
        })







        $("#commit").on("click",function () {

            $.ajax({
                url: "/user/sessionUser.do",
                type: "get",
                dateType: "json",
                async:false,
                success:function (rec) {

                    $.ajax({
                        url: "/bank/findList.do",
                        type: "get",
                        dataType: "json",
                        data: {
                            page: 0,
                            limit: 0,
                        },
                        success: function (r) {
                            var data1 = r.data;
                            $("#balance").val(data1[0].balance)

                            var data = rec.data;
                            var postCode = data.postCode;
                            var userAddress = data.userAddress;
                            $("#postCode").val(postCode);
                            $("#userAddress").val(userAddress);


                            var pw = $("#password2").val();
                            $("#balance").val(data1[0].balance);
                            var id = data1[0].id;

                            if(pw!=data.password2){
                                alert("密码错误")
                            }
                            else if(money>balance){
                                alert("余额不足")
                            }else {
                                $.ajax({
                                    url:"/orders/settlement.do",
                                    type:"post",
                                    dataType:"json",
                                    data:{
                                        id:id,
                                        balance:money,
                                    },
                                    success:function (rs) {
                                        alert("支付成功")
                                        location.href="/html/shopping/cart.html"

                                    }
                                })
                            }
                        }
                    })
                }
            })
        })
    })

    $("#back").on("click",function () {
        location.href="/html/shopping/goodsInfo.html"

    })


</script>

</body>
</html>